//
//  SearchController.m
//  NVAReader
//
//  Created by DuyLK on 6/19/14.
//  Copyright (c) 2014 com.nva.nvareader. All rights reserved.
//

#import "SearchController.h"

@implementation SearchController
-(id) init
{
    self = [super init];
    if (self) {
        data = [[NSMutableArray alloc] init];
    }
    return self;
}

-(void) resetData{
    [data removeAllObjects];
}

-(void) addObjectSearch:(SearchObject *)searchObject
{
    [data addObject:searchObject];
}

-(NSInteger) numberOfRowsInTableView:(NSTableView *)tableView{
    return  [data count];
}

-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    SearchObject *p = [data objectAtIndex:row];
    NSString *identify = [tableColumn identifier];
    return [p valueForKeyPath:identify];
}

-(void) tableView:(NSTableView *)tableView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    SearchObject *p = [data objectAtIndex:row];
    NSString *identify = [tableColumn identifier];
    [p setValue:object forKey:identify];
}
-(SearchObject*)getObjectAtIndex:(NSInteger)index
{
    if ([data count] >0) {
        return [data objectAtIndex:index];
    }else
        return nil;
}
@end
